package bit2;
import java.util.*;
public class bitMain10 {
    public boolean isIsomorphic(String s, String t) {
        HashMap<Character,Character> map1=new HashMap<>();
        HashMap<Character,Character> map2=new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char x=s.charAt(i),y=t.charAt(i);
            if ((map1.containsKey(x)&&map1.get(x)!=y)||(map2.containsKey(y)&&map2.get(y)!=x)){
                return false;
            }
            map1.put(x,y);
            map2.put(y,x);
        }
        return true;
    }
    public int firstUniqChar(String s) {
        HashMap<Character,Integer> map=new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char ch=s.charAt(i);
            if (map.containsKey(ch)){
                int value=map.get(ch);
                map.put(ch,value+1);
            }
            else {
                map.put(ch,1);
            }
        }

        for (int i = 0; i < s.length(); i++) {
            char ch=s.charAt(i);
            if (map.get(ch)==1){
                return i;
            }
        }
        return -1;
    }
    public int[] intersection(int[] nums1, int[] nums2) {
        HashSet<Integer> set1=new HashSet<>();
        HashSet<Integer> set2=new HashSet<>();
        for (int i = 0; i < nums1.length||i<nums2.length; i++) {
            if (i<nums1.length){
                set1.add(nums1[i]);
            }
            if (i<nums2.length){
                set2.add(nums2[i]);
            }
        }
        int[] arr=new int[set1.size()];
        int count=0;
        int[] arr1=new int[set2.size()];
        for (Object num:set1.stream().toArray()) {
            arr[count++]=(int)num;
        }
        count=0;
        for (Object num:set2.stream().toArray()) {
            arr1[count++]=(int)num;
        }
        List<Integer> list=new ArrayList<>();
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr1.length; j++) {
                if (arr[i]==arr1[j]){
                    list.add(arr[i]);
                    break;
                }
            }
        }count=0;
        int a[]=new int[list.size()];
        for (int num:list) {
            a[count++]=num;
        }
        return a;
    }
}
